home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / adaed-1.11 / adaed-1 / Adaed-1.11.0a / adalib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-07  |  10.3 KB  |  407 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9.  
  10. /* liblist.c: translation of code generator read.stl*/
  11.  
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "config.h"
  16. #include "segment.h"
  17. #include "slot.h"
  18. #include "ifile.h"
  19. #include "miscprots.h"
  20. #include "libfprots.h"
  21.  
  22. #ifdef VMS
  23. /*  Temporary removal to avoid missing adalib.h
  24. #include "adalib.h"
  25. #include descrip
  26. */
  27. #endif
  28.  
  29. static void load_library();
  30. static void get_local_ref_maps(IFILE *, int);
  31. static long get_cde_slots(IFILE *, Axq);
  32. static void get_slot(IFILE *, char *);
  33. static char *convert_date(char *);
  34. static char *unit_name_name(char *);
  35. static int is_subunit(char *);
  36. static char *formatted_name(char *);
  37. static char *formatted_stub(char *);
  38.  
  39. IFILE *LIBFILE;
  40. FILE *MALFILE;
  41. #ifdef IBM_PC
  42. /* on the PC, a chdir must be undone before program completes.
  43.  * changed_dir is set when directory changed.
  44.  */
  45. #endif
  46.  
  47. void main(int argc, char **argv)
  48. {
  49.     char *libname;
  50.     char *t_name;
  51.  
  52. #ifdef VMS
  53.     int         status;
  54.     char        buffer[50];
  55.     char    *fname;
  56.     short       rlength;
  57.     struct      dsc$descriptor_s entity_desc;
  58.     struct      dsc$descriptor_s value_desc;
  59.  
  60.     entity_desc.dsc$b_dtype = DSC$K_DTYPE_T;
  61.     entity_desc.dsc$b_class = DSC$K_CLASS_S;
  62.     value_desc.dsc$b_dtype = DSC$K_DTYPE_T;
  63.     value_desc.dsc$b_class = DSC$K_CLASS_S;
  64.     value_desc.dsc$a_pointer = buffer;
  65.     value_desc.dsc$w_length = 50;
  66.     entity_desc.dsc$a_pointer = "LIBRARY";
  67.     entity_desc.dsc$w_length = 7;
  68.     status = CLI$PRESENT(&entity_desc);
  69. #ifdef DEBUG
  70.     printf("LIBRARY status %d\n", status);
  71. #endif
  72.     if (status & 1) {
  73.         status = CLI$GET_VALUE(&entity_desc, &value_desc, &rlength);
  74.         value_desc.dsc$a_pointer[rlength] = '\0';
  75.         fname = strjoin(value_desc.dsc$a_pointer, "");
  76. #ifdef DEBUG
  77.         printf("LIBRARY %s\n", fname);
  78. #endif
  79.     }
  80.     if (chdir(fname)) {
  81.         value_desc.dsc$w_length = rlength;
  82.         LIB$SIGNAL(MSG_NOLIBRARY, 1, &value_desc);
  83.         exit();
  84.     }
  85.     LIBFILE = ifopen(LIBFILENAME, "", "r", "l", 0, 0);
  86. #endif 
  87.  
  88. #ifdef IBM_PC
  89.     fprintf(stderr, "NYU Ada/Ed Librarian Version 1.7.2\n");
  90.     fprintf(stderr, "Copyright (C) 1985-1987 by New York University.\n");
  91. #endif
  92.  
  93. #ifndef VMS
  94.     libname = (char *)0;
  95.     if (argc >1)
  96.         libname = argv[1];
  97.     else {
  98.         libname = getenv("ADALIB");
  99.         if (libname!= (char *)0) {
  100. #ifdef IBM_PC
  101.             fprintf(stderr, "L");
  102. #else
  103.             fprintf(stderr, "l");
  104. #endif
  105.             fprintf(stderr, "ibrary defined by ADALIB: %s\n", libname);
  106.         }
  107.     }
  108.     if (libname == (char *)0) {
  109.         fprintf(stderr, "Usage: adalib [library]\n");
  110.         exit(1);
  111.     }
  112.     t_name = libset(libname);
  113.     LIBFILE = ifopen(LIBFILENAME, "", "r", "l", 0, 0);
  114. #endif
  115.  
  116.     load_library();
  117. #ifdef VMS
  118.     exit();
  119. #else
  120.     exit(0);
  121. #endif
  122. }
  123.  
  124.  
  125. static void load_library()                                /*;load_library*/
  126. {
  127.     /*
  128.      * retrieve information from LIBFILE
  129.      * Called only if lib_option and not newlib.
  130.      */
  131.  
  132.     int        i, j, n, m, unumber, nodes, symbols;
  133.     int        comp_status, unit_count, cur_level;
  134.     char    *comp_date, *status_str, *uname, *aisname, *tmp_str;
  135.     char    *main_string;
  136.     int        is_main, empty_unit_slots, parent;
  137.     int        ignore;
  138.  
  139.  
  140.     unit_count = getnum(LIBFILE, "lib-unit-count");
  141.     n = getnum(LIBFILE, "lib-n");
  142.     empty_unit_slots = getnum(LIBFILE, "lib-empty-slots");
  143.     tmp_str = getstr(LIBFILE, "lib-tmp-str");
  144.     for (i = 1; i <= unit_count; i++) {
  145.         uname = getstr(LIBFILE, "lib-unit-name");
  146.         unumber = getnum(LIBFILE, "lib-unit-number");
  147.         aisname = getstr(LIBFILE, "lib-ais-name");
  148.         comp_date = getstr(LIBFILE, "unit-date");
  149.         symbols = getnum(LIBFILE, "lib-symbols");
  150.         nodes = getnum(LIBFILE, "lib-nodes");
  151.         is_main = getnum(LIBFILE, "lib-is-main");
  152.         if (is_main) {
  153.             if (streq(unit_name_type(uname), "ma"))
  154.                 main_string = "(Interface)";
  155.             else
  156.                 main_string = "  (Main)   ";
  157.         }
  158.         else {
  159.             main_string = "";
  160.         }
  161.         comp_status = getnum(LIBFILE, "lib-status");
  162.         status_str = (comp_status) ? "active  " : "obsolete";
  163.         printf("%8s %11s %-15s %s\n",
  164.             status_str, main_string, convert_date(comp_date),
  165.             formatted_name(uname));
  166.     }
  167.     printf("\n");
  168.     n = getnum(LIBFILE, "lib-n");
  169.     if (n) {
  170.         printf("stubs \n\n");
  171.         for (i = 1; i <= n; i++) {
  172.             uname = getstr(LIBFILE, "lib-unit-name");
  173.             aisname = getstr(LIBFILE, "lib-ais-name");
  174.             parent = getnum(LIBFILE, "lib-parent");
  175.             cur_level = getnum(LIBFILE, "lib-cur-level");
  176.             m = getnum(LIBFILE, "stub-file-size");
  177.             for (j = 1; j <= m; j++)
  178.                 ignore = getnum(LIBFILE, "stub-file");
  179.             printf("%s\n", formatted_stub(uname));
  180.         }
  181.         printf("\n");
  182.     }
  183.     ifclose(LIBFILE);
  184.     return;
  185. #ifdef TBSL
  186.     n = getnum(LIBFILE, "precedes-map-size");
  187.     printf("precedes map\n");
  188.     for (i = 1; i <= n; i += 2) {
  189.         dom = getnum(LIBFILE, "precedes-map-dom");
  190.         m = getnum(LIBFILE, "precedes-map-nelt");
  191.         printf("  %4d:", dom);
  192.         for (j = 1; j <= m; j++) {
  193.             range = getnum(LIBFILE, "precedes-map-ent");
  194.             printf(" %4d", range);
  195.         }
  196.         printf("\n");
  197.     }
  198.     n = getnum(LIBFILE, "compilation_table_size");
  199.     if (n) {
  200.         printf("\ncompilation table\n");
  201.         for (i = 1; i <= n; i++) {
  202.             unum = (int) getnum(LIBFILE, "compilation-table-ent");
  203.             printf("  %d\n", unum);
  204.         }
  205.         printf("\n");
  206.     }
  207.     /* late_instances */
  208.     n = getnum(LIBFILE, "late-instances-size");
  209.     if (n) {
  210.         printf("late instances\n");
  211.         for (i = 1; i <= n; i++) {
  212.             str = (char *) getstr(LIBFILE, "late-instances-str");
  213.             printf("  %s\n", str);
  214.         }
  215.     }
  216.     /* current code segment */
  217.     n = getnum(LIBFILE, "unit-size");
  218.     printf("\ncurrent code segments\n");
  219.     printf("  unit cs\n");
  220.     for (i = 1; i <= n; i++) {
  221.         cs = getnum(LIBFILE, "current-code-segment");
  222.         if (cs) printf("   %d: %d\n", i, cs);
  223.     }
  224.     /* local reference maps */
  225.     n = getnum(LIBFILE, "unit-size");
  226.     get_local_ref_maps(LIBFILE, n);
  227.     cde_pos = get_cde_slots(LIBFILE, axq);
  228.  
  229.  
  230.     /* could free axq_data_slots, etc., but keep for now */
  231.     /* read out LIB_STUB map (always empty for now) */
  232.     ifclose(LIBFILE);
  233.     return;
  234. #endif
  235. }
  236.  
  237. static void get_local_ref_maps(IFILE *ifile, int units)    /*;get_local_ref_map*/
  238. {
  239.     int        unit, defined, i, off, n;
  240.     int        sym_seq, sym_unit;
  241.  
  242.     printf("\nlocal reference maps\n");
  243.     for (unit = 1; unit <= units; unit++) {
  244.         /* ignore empty ref maps (predef units) and obselete units */
  245.         defined = getnum(ifile, "local-ref-map-defined");
  246.         if (!defined) continue;
  247.         printf("%d: ", unit);
  248.         n = getnum(ifile, "local-ref-map-size");
  249.         n = n/2;
  250.         for (i = 1; i <= n; i++) {
  251.             sym_seq = getnum(ifile, "local-ref-map-sym-seq");
  252.             sym_unit = getnum(ifile, "local-ref-map-sym-unit");
  253.             off = getnum(ifile, "local-ref-map-off");
  254.             /* if all three values are zero ignore this entry. It is a fake
  255.              * entry created by put_local_ref_map. see comment there.
  256.              */
  257.             if (sym_seq == 0 && sym_unit == 0 && off == 0) continue;
  258.             printf("%d %d %d ", sym_seq, sym_unit, off);
  259.         }
  260.         printf("\n");
  261.     }
  262.     printf("\n");
  263. }
  264.  
  265. static long get_cde_slots(IFILE *file, Axq axq)                /*;get_cde_slots*/
  266. {
  267.     long    dpos;
  268.     int        n_code, n_data, n_exception;
  269.  
  270.  
  271.     dpos = file->fh_slots;
  272.     /* position to start of slot info */
  273.     ifseek(file, "get-cde-slots-start", dpos, 0);
  274.     n_code = getnum(file, "n-code");
  275.     n_data = getnum(file, "n-data");
  276.     n_exception = getnum(file, "n-exception");
  277.     get_slot(file, "code");
  278.     get_slot(file, "data");
  279.     get_slot(file, "exceptions");
  280.     return dpos; /* return offset of start of slot info */
  281. }
  282.  
  283. static void get_slot(IFILE *file, char *name)                    /*;get_slot*/
  284. {
  285.     /* This procedure reads in the SLOTS information. 
  286.      * Entries are Slots structures. nmax is guess at needed dimension,
  287.      * dim is set to dimension actually found.
  288.      */
  289.  
  290.     int i, n, exists;
  291.     int    slot_seq, slot_unit, slot_number;
  292.     char *slot_name;
  293.  
  294.     n = getnum(file, "slot-entries");
  295.     printf("%s slots \n", name);
  296.     printf("  num seq unit  name\n");
  297.  
  298.     for (i = 1; i <= n; i++) {
  299.         exists = getnum(LIBFILE, "slot-exists");
  300.         if (exists) {
  301.             slot_seq = getnum(LIBFILE, "slot-seq");
  302.             slot_unit = getnum(LIBFILE, "slot-unit");
  303.             slot_number = getnum(LIBFILE, "slot-number");
  304.             slot_name = getstr(LIBFILE, "slot_name");
  305.             printf("  %3d %3d %4d  %s\n",
  306.                 slot_number, slot_seq, slot_unit, slot_name);
  307.         }
  308.     }
  309.     printf("\n");
  310. }
  311.  
  312. static char *convert_date(char *comp_date)                    /*;convert_date*/
  313. {
  314.     static char new_date[15];
  315.     int    i;
  316.  
  317.     if (comp_date == (char *)0)
  318.         return(" ");
  319.     comp_date++;
  320.     comp_date++;
  321.     for (i = 6; i < 8; i++)
  322.         new_date[i] = *comp_date++;
  323.     comp_date++;
  324.     for (i = 0; i < 2; i++)
  325.         new_date[i] = *comp_date++;
  326.     new_date[2] = '/';
  327.     comp_date++;
  328.     for (i = 3; i < 5; i++)
  329.         new_date[i] = *comp_date++;
  330.     new_date[5] = '/';
  331.     new_date[8] = ' ';
  332.     comp_date++;
  333.     for (i = 9; i < 14; i++)
  334.         new_date[i] = *comp_date++;
  335.     new_date[11] = ':';
  336.  
  337.     new_date[14] = '\0';
  338.     return new_date;
  339. }
  340.  
  341. static char *unit_name_name(char *u)                        /*;unit_name_name*/
  342. {
  343.     int    n;
  344.     char    *s1, *s2;
  345.  
  346.     n = strlen(u);
  347.     if (n <= 2)
  348.         return (char *)0;
  349.  
  350.     s1 = u+2;                 /* point to start of name*/
  351.     s2 = strchr(s1, '.');     /* look for dot after first name */
  352.     if (s2 == (char *)0)     /* if no dot take rest of string */
  353.         s2 = u + n;         /* find end */
  354.     n = s2 - s1;
  355.     s2 = emalloc((unsigned) n+1);
  356.     strncpy(s2, s1, n);
  357.     s2[n] = '\0'; /* terminate result */
  358.     return (s2);
  359. }
  360.  
  361. static int is_subunit(char *u)                                    /*;is_subunit*/
  362. {
  363.     /* In C, IS_SUBUNIT is procedure is_subunit():
  364.      *    IS_SUBUNIT(na);           (#na > 2)                          endm;
  365.      */
  366.  
  367.     int    n;
  368.     char    *s1, *s2;
  369.  
  370.     if (u == (char *)0)
  371.         chaos("is_subunit: null pointer");
  372.     n = strlen(u);
  373.     if (n <= 2)
  374.         return FALSE;
  375.     s1 = u + 2; /* point to start of name*/
  376.     s2 = strchr(s1, '.'); /* look for dot after first name */
  377.     if (s2 == (char *)0) /* if no dot take rest of string */
  378.         return FALSE;
  379.     return TRUE; /* if subunit*/
  380. }
  381.  
  382. static char *formatted_name(char *unit)                    /*;formatted_name*/
  383. {
  384.     char *kind, *unit_kind;
  385.  
  386.     kind = unit_name_type(unit);
  387.     if (is_subunit(unit))        unit_kind = "proper body ";
  388.     else if (streq(kind, "sp"))  unit_kind = "package spec ";
  389.     else if (streq(kind, "bo"))  unit_kind = "package body ";
  390.     else if (streq(kind, "ss"))  unit_kind = "subprogram spec ";
  391.     else if (streq(kind, "su"))  unit_kind = "subprogram ";
  392.     else if (streq(kind, "ma"))  unit_kind = "binding unit ";
  393.     else unit_kind = "unit ";
  394.     return strjoin(unit_kind, unit_name_name(unit));
  395. }
  396.  
  397. static char *formatted_stub(char *unit)                        /*;formatted_stub*/
  398. {
  399.     char *kind, *unit_kind;
  400.  
  401.     kind = unit_name_type(unit);
  402.     if (streq(kind, "bo"))  unit_kind = "package (task) stub ";
  403.     else if (streq(kind, "su"))  unit_kind = "subprogram stub ";
  404.     else unit_kind = "stub ";
  405.     return strjoin(unit_kind, unit_name_name(unit));
  406. }
  407.